#ifndef CUBE_LEVEL_H_
#define CUBE_LEVEL_H_

#define CORRECT_PATH		-1
#define BRANCH_PATH			-2
#define	START_POS			-3
#define END_POS				-4

enum eFace
{
	FACE_BOTTOM,
	FACE_TOP,
	FACE_LEFT,
	FACE_RIGHT,
	FACE_FRONT,
	FACE_BACK,
	FACE_NUM
};

struct LEVEL_DESC
{
	float		straightnessWeight;
	float		directionalWeight;
	float		nSize;
	BYTE		nGrid;
	BYTE		nBranch;
	int			restrictTime;
};

class Level
{
public :
	explicit Level( int level );
	~Level();

	void									Initialize( const LEVEL_DESC& desc );
	bool									IsMoveableTo( Point point );
	void									UpdateTime( float deltaMilliSec ){ _elaspedTime += deltaMilliSec; }

	const BYTE								GetLevel(){ return _level; }
	float									GetElaspedTime(){ return _elaspedTime; }
	Point									GetEndPos(){ return _endPos; }
	WORD									GetGridCount(){ return _nGrid; }
	Point									GetPlayerPos(){ return _currentPos; }
	int										GetRestrictTime(){ return _restrictTime; }
	Point									GetStartPos(){ return _startPos; }
	eFace									GetVisibleFace();
	char*									GetVisibleMap(){ return _visibleMap; }

	void									OnArrowKeyPressed( const std::string& dir, const D3DXVECTOR3& view );

	void									SetPlayerPos( const Point& point ){ _currentPos = point; }
	void									SetVisibleFace( const D3DXVECTOR3& view );
	void									SetVisibleMap( eFace face );

private :
	bool									CheckNodeValidation( const Point& point, bool* visited );
	void									CreateBranch( int nBranch, int maxBranchLength, bool* visited );
	void									CreateMap();
	void									CreatePath( float dWeight, float sWeight, bool* visited );
	void									DistributeValue( std::vector< int >& list, int nSplit, int value, int lower, int upper );
	void									DrawOut( std::vector< int >& list, int nDrawOuts, int lower, int upper );

	std::vector< std::vector< Point >* >	_branchList;
	std::vector< Point >					_correctPath;
	Point									_currentPos;
	float									_elaspedTime;
	Point									_endPos;
	const BYTE								_level;
	char*									_map[ FACE_NUM ];
	WORD									_nGrid;
	int										_restrictTime;
	Point									_startPos;
	int										_visibleFace;
	char*									_visibleMap;

};

#endif